//引入二次封装的axios接口
import request from "@/utils/request";
//引入定义好类型
import type { resDataList, AttrResponesData, Attr } from "./type";
//枚举
enum API {
  C1_URL = "/admin/product/getCategory1",
  C2_URL = "/admin/product/getCategory2/",
  C3_URL = "/admin/product/getCategory3/",
  //获取分类数据接口
  GETDATALIST_URL = "/admin/product/attrInfoList/",
  //添加或者修改三级分类接口
  ADDORUPDATE_URL = "/admin/product/saveAttrInfo",
  //删除产品信息接口
  DELETE_URL = "/admin/product/deleteAttr/",
}

//获取一级数据
export const getCategory1 = () => request.get<any, resDataList>(API.C1_URL);
//获取二级数据
export const getCategory2 = (category1Id: number | string) =>
  request.get<any, resDataList>(API.C2_URL + category1Id);
//获取三级数据
export const getCategory3 = (category2Id: number | string) =>
  request.get<any, resDataList>(API.C3_URL + category2Id);
//获取分类数据
export const getDataList = (
  category1Id: number | string,
  category2Id: number | string,
  category3Id: number | string,
) =>
  request.get<any, AttrResponesData>(
    API.GETDATALIST_URL + category1Id + "/" + category2Id + "/" + category3Id,
  );
//添加或者修改三级分类
export const addOrUpdateAttr = (data: Attr) =>
  request.post<any, any>(API.ADDORUPDATE_URL, data);
//删除产品信息接口
export const deleteAttr = (attrId: number) =>
  request.delete<any, any>(API.DELETE_URL + attrId);
